package com.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/register")
public class RegisterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //从注册页面获取用户名和密码的参数
        String uname = req.getParameter("uname");
        String pwd = req.getParameter("pwd");
        if (uname !=null && uname.length() !=0 && pwd !=null && pwd.length() !=0) {
            HttpSession session = req.getSession();
            session.setAttribute("uname",uname);
            session.setAttribute("pwd",pwd);
            resp.sendRedirect("login.jsp");
        } else {
            resp.sendRedirect("register.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {super.doPost(req, resp);

    }
}
